<?php

namespace App\Admin\Controllers;

use App\Admin\Extensions\Actions\RefundAction;
use App\Http\Controllers\Controller;
use App\Models\Arenacontest;
use App\Models\ArenacontestUser;
use App\Models\CityList;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
use App\Models\WechatUser;
use App\Models\ArenacontestUserUser;

class ArenacontestTransactionController extends Controller
{
    use HasResourceActions;

    private $name = '擂台赛交易';

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header($this->name)
            ->description(trans('admin.list'))
            ->body($this->grid());
    }


    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ArenacontestUser);
        $grid->disableCreateButton();
        //禁用行选择checkbox
        $grid->disableRowSelector();
        //禁用行选择器
        $grid->disableColumnSelector();
        //设置分页选择器选项
        $grid->filter(function ($filter) {
            // 去掉默认的id过滤器
            $filter->disableIdFilter();
            // 在这里添加字段过滤器
            $filter->like('wxcode', '微信号');
            $filter->like('wxcode', '联系方式');
            $filter->like('wxcode', '订单编号');
            $filter->like('wxcode', '微信支付单号');
            $filter->equal('pay_status','缴费状态')->select([
                10 => "待缴费",
                20 => "已缴费",
                30 => "已退费",
            ]);
        });
        $grid->arenacontest()->title('擂台赛');
        $grid->user()->name('用户');
        $grid->wxcode('微信号');
        $grid->contact('联系方式');
        $grid->ordersn('订单编号');
        $grid->price('金额');
        $grid->transid('微信支付单号');
        $grid->pay_status('缴费状态')->display(function ($status) {
            return ArenacontestUser::getpayStatus($status);
        });
        $grid->model()->orderBy('id', 'desc');

        $grid->actions(function ($actions) {
            // 去掉删除
            $actions->disableDelete();
            // 去掉编辑
            $actions->disableEdit();
            // 去掉查看
            $actions->disableView();
            if ($actions->row['pay_status'] == 20 && $actions->row['price']>0) {
                $actions->append(new RefundAction($actions->getKey()));
            }
        });
        return $grid;
    }


}
